<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('调整申请')"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="white-bg">

<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-standingBook-edit" th:object="${standingBookVo}">
        <input name="p_B_again" id="again" type="hidden">
        <input name="id" th:field="*{id}" type="hidden">
        <input name="csry" th:field="*{csry}" type="hidden">
        <input type="hidden" name="saveEntity" value="true"/>

        <h4 class="form-header h4">基本信息</h4>
        <div class="form-group">
            <label class="col-sm-3 control-label ">编号：</label>
            <div class="col-sm-8">
                <input class="form-control" th:field="*{numberText}" type="text" name="numberText" id="numberText" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">项目名称：</label>
            <div class="col-sm-8">
                <input class="form-control" th:field="*{proName}" type="text" name="proName" id="proName" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">工程公司：</label>
            <div class="col-sm-8">
                <select name="compName" th:with="type=${@dict.getType('company')}" class="form-control"
                        onchange="createNumber()">
                    <option value="">请选择</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictLabel}"
                            th:title="${dict.dictValue}" th:field="*{compName}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">商务经理：</label>
            <div class="col-sm-8">
                <input class="form-control" th:value="${createByName}" type="text" name="swjl" id="swjl" readonly  />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">审核内容：</label>
            <div class="col-sm-8">
                <input class="form-control" th:field="*{auditContent}" type="text" name="auditContent" id="auditContent" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">分包班组信息：</label>
            <div class="col-sm-8">
                <input class="form-control" th:field="*{teamInfo}" type="text" name="teamInfo" id="teamInfo" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">申请金额：</label>
            <div class="col-sm-8">
                <input class="form-control" th:field="*{applyMoney}" type="text" name="applyMoney" id="applyMoney" />
            </div>
        </div>
        <div class="col-12" style="text-align: center;margin: 0 auto;">
            <a class="btn btn-success" onclick="again(true)">重新申请</a>
        </div>
    </form>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:src="@{/js/activiti.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "settlement"
    var historyData;

    $(function () {
        var user = [[${user}]];
        $("#swjl").val(user.userName);
    });

    $("#form-standingBook-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        $.modal.close();
    }

    function getDataByTitle() {
        var id = $("#last").val();
        for (var i = 0; i < historyData.length; i++) {

            if (historyData[i].id == id) {
                $("#lastPlan").val(historyData[i].nextPlan);
            }
        }
        $("#missmodal1").click();
    }

    function again(again){
        $.modal.confirm("数据是否已保存?", function () {
            $("#again").val(again);
            if ($.validate.form()) {
                var taskId = [[${taskId}]];
                $.operate.save(prefix + "/complete/" + taskId, $('#form-standingBook-edit').serialize());
            }
        });


    }

    function save(){
        $.ajax({
            type : "post",
            url : prefix + "/edit.ajax",
            data : {
                "id": $("#id").val(),
                "numberText": $("#numberText").val(),
                "proName": $("#proName").val(),
                "auditContent": $("#auditContent").val(),
                "teamInfo": $("#teamInfo").val(),
                "applyMoney": $("#applyMoney").val()
            },
            success : function(data) {
                if(data.code == 0){
                    alert("保存成功");
                    location.reload();
                }else{
                    alert("保存失败");
                }
            }
        });
    }

    function createNumber() {
        var compTitle = $("select[name='compName'] option:selected").attr("title");
        var compName = $("select[name='compName'] option:selected").val();
        var proName = $("input[name='proName']").val();
        if (typeof(compName) != "undefined" && compName != '' && proName != '') {
            $.ajax({
                url: prefix + '/createNumber',
                data: {
                    compTitle: compTitle,
                    compName: compName,
                    proName: proName,
                },
                type: 'POST',
                success: function (data) {
                    $("input[name='numberText']").val(data);
                }
            });
        } else {
            $("input[name='numberText']").val("");
        }
    }



</script>
</body>
</html>
